package com.neusoft.yuejian_6.activity;

import android.app.Activity;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.neusoft.yuejian_6.R;
import com.squareup.picasso.Picasso;




public class TrainDetailActivity extends Activity {

    private ImageView train_pic;
    private TextView train_intro;
    private TextView train_phone;
    private TextView train_address;
    private Button baoming_button;
    private int train_id;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_train_detail);
        initView();
        initEvents();
        getTrainData();
    }

    private void getTrainData() {
        Bundle bundle = this.getIntent().getExtras();
        train_id = bundle.getInt("train_id");
        String trainintro = bundle.getString("train_intro");
        String trainaddress = bundle.getString("train_address");
        String trainphone = bundle.getString("train_phone");
        // int tprice = bundle.getInt("t_price");
        String tpic = "http://10.0.2.2/neu1_yuejian/Public/Admin/photo/" + bundle.getString("train_pic");
        //String ttime = bundle.getString("t_time");
        //System.out.print("taddress");
        train_intro.setText(trainintro);
        train_address.setText(trainaddress);
        train_phone.setText(trainphone);
        // t_price.setText(tprice+"");
        //System.out.print("train_intro");
        //   t_time.setText(ttime);
        Picasso.with(this).load(tpic).into(train_pic);
    }


    private void initView() {

        train_pic = (ImageView) findViewById(R.id.train_pic);
        train_intro = (TextView) findViewById(R.id.train_intro);
        train_address = (TextView) findViewById(R.id.train_address);
        train_phone = (TextView) findViewById(R.id.train_phone);
        baoming_button = (Button) findViewById(R.id.baoming_button);
    }

    public void initEvents() {
        baoming_button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(TrainDetailActivity.this, EnterTrainActivity.class);
                Bundle bundle = new Bundle();
                bundle.putInt("train_id",train_id);

                intent.putExtras(bundle);
                startActivityForResult(intent, 1);

            }
        });

        /**
         * ATTENTION: This was auto-generated to implement the App Indexing API.
         * See https://g.co/AppIndexing/AndroidStudio for more information.
         */

    }
}
